/* Original Author:  Dominick O'Dierno
 * Date: 2007   odiernod@gmail.com     --Originally intended for use with DOMercury:  http://www.odierno.com/domercury
 * Description: Handles whether file paths are valid, and turns certain special path text (i.e "mydocs" into valid file paths)
 * 
 * --CHANGELOG--
 * 
 * 
 * --TODO--
 * Include environment variables
 * */
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace DOMercury.Managers
{
    public static class PathFinder
    {
        public static string FindPath(string path)
        {
            if (!((System.IO.File.Exists(path)) || (System.IO.Directory.Exists(path))))
            {
                try
                {
                    switch (path.ToLower())
                    {
                        case "mydocs":
                        case "documents":
                        case "my documents":
                            path = "MyDocuments"; break;
                        case "program files":
                            path = "ProgramFiles"; break;
                        case "pics":
                        case "mypics":
                        case "my pictures":
                            path = "MyPictures"; break;
                        case "music":
                        case "my music":
                            path = "MyMusic"; break;
                        default: break;

                    }
                    List<string> SpecialPaths = new List<string>();
                    SpecialPaths.Add("mydocuments");
                    SpecialPaths.Add("programfiles");
                    SpecialPaths.Add("mypictures");
                    SpecialPaths.Add("mymusic");
                    SpecialPaths.Add("favorites");
                    SpecialPaths.Add("recent");
                    SpecialPaths.Add("personal");
                    if (SpecialPaths.Contains(path.ToLower()))
                    {
                        Environment.SpecialFolder sp = ((System.Environment.SpecialFolder)(Enum.Parse(typeof(System.Environment.SpecialFolder), path, true)));
                        return Environment.GetFolderPath(sp);
                    }
                    return path;
                }
                catch
                {
                    //In future check special paths
                    return path;
                }
            }
            else
            {
                return path;
            }
        }

        public static bool IsPath(string path)
        {

            if (Directory.Exists(FindPath(path)) || File.Exists(FindPath(path)))
            {
                return true;
            }
            return false;
        }
    }
}
